#Include "Protheus.ch"

User Function AVI00449()

Local aArea    := GetArea()
Local nAnos  := 0
Local nBase  := 0
Local nTeto  := 0
Local nPerc  := 0
Local nCalc  := 0

dbSelectArea("RCE")
RCE->(dbSetOrder(1))  // RCE_FILIAL+RCE_CODIGO

IF RCE->(MsSeek(xFilial("RCE") + SRA->RA_SINDICA))

	nAnos := Int(DataHora2Val(SRA->ADMISSA, 0, dDataBase, 0, "M") / 12)
	nBase := RCE->RCE_ZZBCAL
	nTeto := RCE->RCE_ZTETO
	
	IF nAnos >= 5 .And. nAnos <= 9
		nPerc := RCE->RCE_ZPER05
	ElseIF nAnos >= 10 .And. nAnos <= 14
		nPerc := RCE->RCE_ZPER10
	ElseIF nAnos >= 15 .And. nAnos <= 19
		nPerc := RCE->RCE_ZPER15
	ElseIF nAnos >= 20
		nPerc := RCE->RCE_ZPER20
	EndIF
		
	nCalc := nBase + ((nBase / 100) * nPerc)
	nCalc := IF(nCalc > nTeto, nTeto, nCalc)
	
	FGERAVERBA("050", nCalc, nAnos, , SRA->RA_CC, "V", "C", , , , .T., )

EndIF

RCE->(dbCloseArea())

RestArea(aArea)

Return Nil